# -*- coding: UTF-8 -*-
from django.contrib import admin
from django.utils.translation import gettext_lazy as _
from .models import QualityStandard, QualityTest, QualityReport


@admin.register(QualityStandard)
class QualityStandardAdmin(admin.ModelAdmin):
    list_display = ['name', 'code', 'version', 'status', 'created_at']
    list_display_links = ['name']
    search_fields = ['name', 'code', 'description']
    list_filter = ['status', 'version', 'created_at']
    date_hierarchy = 'created_at'
    
    fieldsets = (
        (_('基本信息'), {
            'fields': ('name', 'code', 'version', 'description')
        }),
        (_('标准信息'), {
            'fields': ('status', 'standard_type', 'test_method')
        }),
        (_('其他信息'), {
            'fields': ('note',),
            'classes': ('collapse',)
        }),
    )


@admin.register(QualityTest)
class QualityTestAdmin(admin.ModelAdmin):
    list_display = ['test_no', 'product', 'standard', 'test_date', 'result', 'tester']
    list_display_links = ['test_no']
    search_fields = ['test_no', 'product__name', 'standard__name']
    list_filter = ['result', 'test_date', 'tester', 'standard']
    date_hierarchy = 'test_date'
    
    fieldsets = (
        (_('基本信息'), {
            'fields': ('test_no', 'product', 'standard', 'test_date', 'tester')
        }),
        (_('测试结果'), {
            'fields': ('result', 'test_value', 'remarks')
        }),
        (_('其他信息'), {
            'fields': ('note',),
            'classes': ('collapse',)
        }),
    )


@admin.register(QualityReport)
class QualityReportAdmin(admin.ModelAdmin):
    list_display = ['report_no', 'test', 'report_date', 'status', 'created_by']
    list_display_links = ['report_no']
    search_fields = ['report_no', 'test__test_no']
    list_filter = ['status', 'report_date', 'created_by']
    date_hierarchy = 'report_date'
    
    fieldsets = (
        (_('基本信息'), {
            'fields': ('report_no', 'test', 'report_date', 'status')
        }),
        (_('报告内容'), {
            'fields': ('content', 'conclusion', 'recommendations')
        }),
        (_('系统信息'), {
            'fields': ('created_by',),
            'classes': ('collapse',)
        }),
    ) 